﻿@{
    ViewBag.Title = "任务详情";
    Layout = "~/Views/Shared/PlanPartial/_LayoutDetail_Task.cshtml";
}

@using Wicresoft.UnifyShow.Business;
@using Wicresoft.UnifyShow.Utility;

@{
    var taskType = (int)ViewData["TaskType"];
    var isDialy = taskType == (int)EnumUtility.TaskType.Daily;
    var isThird = taskType == (int)EnumUtility.TaskType.ThirdParty;
    var isGeneral = taskType == (int)EnumUtility.TaskType.General;

    var Model = ViewData["Model"] as TaskModel;
    var isView = Model != null;

    var IsTaskEnd = (bool)ViewData["TaskIsEnd"];
}

<script type="text/javascript">
    var comboboxOptions = [{
        optionVal: '正常',
        optionName: '正常'
    }, {
        optionVal: '部分正常',
        optionName: '部分正常'
    }, {
        optionVal: '不正常',
        optionName: '不正常'
    }];

    var TaskD = {};

    TaskD.disabledControl = function (excludeControlIDs) {

        var controls = $('body').find('input,select,textarea');
        controls.each(function () {
            if ($.inArray($(this).attr('id'), excludeControlIDs) < 0) {
                $(this).attr('disabled', true);
            }
        });

        $('.easyui-datebox').datebox({ 'disabled': true });
        $('.validatebox-text').attr('disabled', true);
    };

    $(function () {

        var isEnd = $('#IsTaskEnd').val() == 'True';

        var excludeControls = [];

        if (!isEnd) {
            excludeControls.push('taskStatus', 'btnSave', 'btnCancel', 'fileUpload', 'upload');
        }

        TaskD.disabledControl(excludeControls);
    });
</script>

<style type="text/css">
    .datagrid-row-selected { background: #F5EDB5; }
    .datagrid-row-error { background: #E7C436; }
</style>

@if (isDialy)
{ 
    <div class="parameter" style="padding: 10px 0;">
        <div class="parameter_name">
            待巡检对象：
        </div>
        <span style="color: red; font-size: 12px; font-weight: normal;">(点击进行编辑)</span>
    </div>
    <div class="outer_border padding10">
        <div class="padding10-5" data-container="BusinessInsp">
            <input type="hidden" id="taskInspDetail" value="@(isView ? Model.TaskDetail : "")" />
            <table id="BusinessSystems" class="" title="业务系统"
                fitcolumns="true" singleselect="true" data-field="BusinessInsp">
                <thead>
                    <tr>
                        <th field="AppSystemName" width="160">业务系统名称</th>
                        <th field="IPAddress" width="160">IP地址</th>
                        <th field='IsUsable' data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="190">业务系统是否可用</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="190">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="190">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="Environment">
            <table id="RoomEnvironment" class="" title="机房保障"
                fitcolumns="true" singleselect="true" data-field="Environment">
                <thead>
                    <tr>
                        <th field="IsAirConditioning" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">精密空调是否有异常</th>
                        <th field="IsTemperature" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">温度湿度是否符合要求</th>
                        <th field='IsUPS' data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">UPS电源是否有故障</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="ServerInsp">
            <table id="Server" class="" title="服务器"
                fitcolumns="true" singleselect="true" data-field="ServerInsp">
                <thead>
                    <tr>
                        <th field="DeviceName" width="120" rowspan="2">主机名</th>
                        <th field="Item" width="120" rowspan="2">机型</th>
                        <th field="IPAddress" width="120" rowspan="2">IP地址</th>
                        <th field="Usaged" width="120" rowspan="2">用途</th>
                        <th width="160" colspan="2">系统错误报告</th>
                        <th width="160" colspan="2">系统性能报告</th>
                        <th width="160" colspan="1">文件系统</th>
                        <th width="160" colspan="1">通信</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160" rowspan="2">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160" rowspan="2">备注</th>
                    </tr>
                    <tr>
                        <th field="IsHardError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">有否硬件故障</th>
                        <th field="IsSoftError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">有否软件故障</th>

                        <th field="HasCpuError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">有否CPU利用瓶颈</th>
                        <th field="HasMemoryError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">有否内存利用瓶颈</th>

                        <th field="HasSpaceError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">有否可用空间不足</th>

                        <th field="IsNetError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}">网络联通是否异常</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="NetInsp">
            <table id="Network" class="" title="网络设备"
                fitcolumns="true" singleselect="true" data-field="NetInsp">
                <thead>
                    <tr>
                        <th field="DeviceName" width="120">设备名称</th>
                        <th field="ManufacturerName" width="120">设备品牌</th>
                        <th field="Model" width="120">型号</th>
                        <th field="IPAddress" width="120">管理IP</th>
                        <th field="Look" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">设备外观</th>
                        <th field="HardInfo" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">硬件基本信息</th>
                        <th field="Running" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">运行状态</th>
                        <th field="Port" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">设备端口</th>
                        <th field="Routing" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">路由协议</th>
                        <th field="OSPF" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">OSPF邻居状态</th>
                        <th field="VRRP" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">VRRP状态</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="SafetyInsp">
            <table id="Safety" class="" title="安全设备"
                fitcolumns="true" singleselect="true" data-field="SafetyInsp">
                <thead>
                    <tr>
                        <th field="DeviceName" width="120">设备名称</th>
                        <th field="ManufacturerName" width="120">设备品牌</th>
                        <th field="Model" width="120">型号</th>
                        <th field="IPAddress" width="120">管理IP</th>
                        <th field="HardInfo" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">硬件设备</th>
                        <th field="Running" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">运行状态</th>
                        <th field="Network" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">网络连通性</th>
                        <th field="Interface" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">接口模块</th>
                        <th field="ErrorLog" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">异常日志</th>
                        <th field="VersionInfo" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">版本信息</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="DBInsp">
            <table id="DataBase" class="" title="数据库"
                fitcolumns="true" singleselect="true" data-field="DBInsp">
                <thead>
                    <tr>
                        <th field="DbAndVersion" width="120">数据库版本</th>
                        <th field="IPAddress" width="120">IP地址</th>
                        <th field="Usaged" width="120">用途</th>
                        <th field="HasUsableError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否可用性故障</th>
                        <th field="HasSpaceError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否表空间不足</th>
                        <th field='HasPerfError' data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否性能故障</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="MiddleWareInsp">
            <table id="Middleware" class="" title="中间件"
                fitcolumns="true" singleselect="true" data-field="MiddleWareInsp">
                <thead>
                    <tr>
                        <th field="MidAndVersion" width="120">中间件版本</th>
                        <th field="IPAddress" width="120">IP地址</th>
                        <th field="Usaged" width="120">用途</th>
                        <th field="HasProcessError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否中间件进程异常</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="StorageInsp">
            <table id="Storage" class="" title="存储"
                fitcolumns="true" singleselect="true" data-field="StorageInsp">
                <thead>
                    <tr>
                        <th field="Model" width="120">存储型号</th>
                        <th field="IPAddress" width="120">管理IP地址</th>
                        <th field="HasHardError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否硬件故障</th>
                        <th field="HasPerfError" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否性能故障</th>
                        <th field="HasLog" data-options="align:'center',editor:{type:'checkbox',options:{on:'是',off:'否'}}" width="160">有否告警日志</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="padding10-5" data-container="BackupInsp">
            <table id="BackupSys" class="" title="备份"
                fitcolumns="true" singleselect="true" data-field="BackupInsp">
                <thead>
                    <tr>
                        <th field="DbAndVersion" width="120">数据库版本</th>
                        <th field="IPAddress" width="120">IP地址</th>
                        <th field="Usaged" width="120">用途</th>
                        <th field="Summary" data-options="editor:{type:'combobox',options:{valueField:'optionVal',textField:'optionName',data:comboboxOptions}}" width="160">备份巡检总结</th>
                        <th field="Remark" data-options='editor:"text"' width="160">备注</th>
                    </tr>
                </thead>
            </table>
        </div>
        <iframe name="exportFrame" id="exportFrame" src="/PlanManagement/ExportInspectionToExcel" border="0" frameborder="0" style="border: none;height:50px;"></iframe>
    </div>
    
    <script type="text/javascript">
        $.extend($.fn.datagrid.methods, {
            editCell: function (jq, param) {
                return jq.each(function () {
                    var opts = $(this).datagrid('options');
                    var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                    for (var i = 0; i < fields.length; i++) {
                        var col = $(this).datagrid('getColumnOption', fields[i]);
                        col.editor1 = col.editor;
                        if (fields[i] != param.field) {
                            col.editor = null;
                        }
                    }
                    $(this).datagrid('beginEdit', param.index);
                    for (var i = 0; i < fields.length; i++) {
                        var col = $(this).datagrid('getColumnOption', fields[i]);
                        col.editor = col.editor1;
                    }
                });
            }
        });

        //保存任务详情 
        var saveTask = function () {
            
            //结束所有的编辑
            $('[data-field]').each(function () {
                var id = $(this).attr('id');
                var rows = $('#' + id).datagrid('getRows').length;
                for (var i = 0; i < rows; i++) {
                    $('#' + id).datagrid('endEdit', i);
                }
            });

            var data = {};

            //任务巡检对象
            $('[data-field]').each(function () {
                var id = $(this).attr('id'),
                    propName = $(this).attr('data-field');

                if (propName) {
                    if ($(this)[0].tagName.toUpperCase() == "TABLE") {
                        data[propName] = $('#' + id).datagrid('getData').rows;
                    }
                }
            });

            data["TaskDetail"] = JSON.stringify(data);

            taskSave(data, null);
        };

        //将巡检对象导出到excel
        var exportExcel = function () {
            //结束所有的编辑
            $('[data-field]').each(function () {
                var id = $(this).attr('id');
                var rows = $('#' + id).datagrid('getRows').length;
                for (var i = 0; i < rows; i++) {
                    $('#' + id).datagrid('endEdit', i);
                }
            });

            var data = {};

            //任务巡检对象
            $('[data-field]').each(function () {
                var id = $(this).attr('id'),
                    propName = $(this).attr('data-field');

                if (propName) {
                    if ($(this)[0].tagName.toUpperCase() == "TABLE") {
                        data[propName] = $('#' + id).datagrid('getData').rows;
                    }
                }
            });

            return data;

        };

        var editIndex = undefined;
        TaskD.endEditing = function (tableID) {
            if (editIndex == undefined) { return true }
            if ($('#' + tableID).datagrid('validateRow', editIndex)) {
                $('#' + tableID).datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            }
            return false;
        };

        var defaultCheckNoValue = "否", defaultCheckYesValue = "是", defaultSelectValue = "正常";
        var usingCheckYesDefault = [
            "BusinessInsp.IsUsable", "Environment.IsTemperature"
        ];

        var usingCheckNoDefault = [
            "Environment.IsAirConditioning", "Environment.IsUPS", "ServerInsp.IsHardError",
            "ServerInsp.IsSoftError", "ServerInsp.HasCpuError", "ServerInsp.HasMemoryError",
            "ServerInsp.HasSpaceError", "ServerInsp.IsNetError", "DBInsp.HasUsableError", "DBInsp.HasSpaceError",
            "DBInsp.HasPerfError", "MiddleWareInsp.HasProcessError", "StorageInsp.HasHardError", "StorageInsp.HasPerfError",
            "StorageInsp.HasLog"
        ];
        var usingSelectDefault = [
            "NetInsp.Look", "NetInsp.HardInfo", "NetInsp.Running", "NetInsp.Port",
            "NetInsp.Routing", "NetInsp.OSPF", "NetInsp.VRRP", "SafetyInsp.HardInfo", "SafetyInsp.Running",
            "SafetyInsp.Network", "SafetyInsp.Interface", "SafetyInsp.ErrorLog", "SafetyInsp.VersionInfo"
        ];

        var checkErrorRow = function (target, rowData, rowIndex) {
            var that = target;
            var groupName = $(target).attr('data-field');
            var flag = true;
            $.each(rowData, function (i, change) {
                var fieldName = groupName + "." + i;
                if (i == "Summary" && change != defaultSelectValue
                    || ($.inArray(fieldName, usingCheckYesDefault) >= 0 && change != defaultCheckYesValue)
                    || ($.inArray(fieldName, usingCheckNoDefault) >= 0 && change != defaultCheckNoValue)
                    || ($.inArray(fieldName, usingSelectDefault) >= 0 && change != defaultSelectValue)) {
                    flag &= false;
                }

                if (!flag) {
                    $(that).datagrid('getPanel').find('[datagrid-row-index="' + rowIndex + '"]').addClass('datagrid-row-error');
                } else {
                    $(that).datagrid('getPanel').find('[datagrid-row-index="' + rowIndex + '"]').removeClass('datagrid-row-error');
                }
            });
        };

        $.fn.datagrid.defaults.view.onAfterRender = function (target) {
            var fieldName = $(target).attr('data-field');
            var rowDatas = $(target).datagrid('getData').rows;
            $.each(rowDatas, function (i, rowData) {
                checkErrorRow(target, rowData, i);
            });
        };

        TaskD.RegisterGrid = function (tableID, canEdit) {
            $('#' + tableID).datagrid({
                onClickCell: function (index, field) {
                    if (TaskD.endEditing(tableID) && canEdit) {
                        $(this).datagrid('selectRow', index)
                               .datagrid('editCell', { index: index, field: field });
                        editIndex = index;
                    }
                },
                onLoadSuccess: function (data) {
                    $('.datagrid-btable').find('td').each(function () {
                        $(this).attr('title', $(this).text());
                    });
                },
                //不等于默认值之后给该行加深底色
                onAfterEdit: function (rowIndex, rowData, changes) {
                    checkErrorRow(this, rowData, rowIndex);
                }
            });
        };


        $(function () {
            var isEnd = $('#IsTaskEnd').val() == 'True';

            var extendDefaultData = function (fieldName, data) {

                $.each(data, function (i, _data) {

                    _data["Summary"] = _data["Summary"] || defaultSelectValue;

                    $.each(usingCheckYesDefault, function (j, field) {
                        var fieldGroup = field.split('.');
                        if (fieldGroup && fieldGroup.length == 2) {
                            var _groupName = fieldGroup[0], _fieldName = fieldGroup[1];
                            if (fieldName == _groupName) {
                                _data[_fieldName] = _data[_fieldName] || defaultCheckYesValue;
                            }
                        }
                    });

                    $.each(usingCheckNoDefault, function (j, field) {
                        var fieldGroup = field.split('.');
                        if (fieldGroup && fieldGroup.length == 2) {
                            var _groupName = fieldGroup[0], _fieldName = fieldGroup[1];
                            if (fieldName == _groupName) {
                                _data[_fieldName] = _data[_fieldName] || defaultCheckNoValue;
                            }
                        }
                    });

                    $.each(usingSelectDefault, function (j, field) {
                        var fieldGroup = field.split('.');
                        if (fieldGroup && fieldGroup.length == 2) {
                            var _groupName = fieldGroup[0], _fieldName = fieldGroup[1];
                            if (fieldName == _groupName) {
                                _data[_fieldName] = _data[_fieldName] || defaultSelectValue;
                            }
                        }
                    });
                });

                return data;
            };

            var detail = $('#taskInspDetail').val();
            if (detail == "") {
                $('[data-container]').hide();
                $('#exportFrame').hide();
                return;
            }



            if (detail != "") {
                var detailData = JSON.parse(detail);
                var isEmpty = true;
                $.each(detailData, function (fieldName, data) {
                    if ($('[data-field="' + fieldName + '"]').length) {

                        var tableID = $('[data-field="' + fieldName + '"]').attr('id');

                        var registerOptions = {
                            onClickCell: function (index, field) {
                                if (TaskD.endEditing(tableID) && !isEnd) {
                                    $(this).datagrid('selectRow', index)
                                           .datagrid('editCell', { index: index, field: field });
                                    editIndex = index;
                                }
                            },
                            onLoadSuccess: function (data) {
                                $('.datagrid-btable').find('td').each(function () {
                                    $(this).attr('title', $(this).text());
                                });
                            },
                            //不等于默认值之后给该行加深底色
                            onAfterEdit: function (rowIndex, rowData, changes) {
                                checkErrorRow(this, rowData, rowIndex);
                            }
                        };

                        //机房环境显示控制 如果三个都是false 表示不检查
                        if (fieldName == "Environment" && !$.isArray(data)) {
                            if (!(data["AirConditioning"] || data["Temperature"] || data["UPS"])) {
                                $('[data-container="' + fieldName + '"]').hide();
                                $('[data-field="' + fieldName + '"]').datagrid(registerOptions);
                                return;
                            } else isEmpty = false;
                        }

                        if (!$.isArray(data)) { data = [data]; }

                        if (data.length == 0) {
                            $('[data-container="' + fieldName + '"]').hide();
                        } else isEmpty = false;


                        $('[data-field="' + fieldName + '"]').datagrid($.extend({}, {
                            data: extendDefaultData(fieldName, data)
                        }, registerOptions));

                    }
                });

                //没有巡检对象，隐藏导出按钮
                if (isEmpty) {
                    $('#exportFrame').hide();
                }
            }
        });
    </script>
}

@section TypeAndLocation
    {
    @if (isGeneral || isThird)
    {
        <div class="parameter two-cols">
            <div class="parameter_name">任务类型：</div>
            <div class="parameter_input">
                <input type="text" data-model-source="JobTypeName" value="@(isView ? Model.JobTypeName : "")" />
            </div>
        </div>

        <div class="parameter two-cols">
            <div class="parameter_name">任务位置：</div>
            <div class="parameter_input">
                <input type="text" data-model-source="LocationName" value="@(isView ? Model.LocationName : "")" />
            </div>
        </div>
    }

}

@if (isGeneral)
{ 
    <div class="parameter">
        <div class="parameter_name">相关文件：</div>
    </div>
    
    <div class="padding10">
        <table id="JobFileList" class="easyui-datagrid" title="文件列表"
            fitcolumns="true" singleselect="true" url="/PlanManagement/GetFileListUsingJobID">
            <thead>
                <tr>
                    <th field="ID" hidden="true"></th>
                    <th field="FileName" width="160" formatter="addLink">文件名称</th>
                    <th field="UploadTime" width="160" formatter="DateFormate">上传时间</th>
                    <th field="UpLoadUserID" hidden="true"></th>
                    <th field="UpLoadUserName" width="160">上传人</th>
                </tr>
            </thead>
        </table>
    </div>
}

@{
    var fileList = ViewData["FileList"] as string;
    var currentUser = ViewData["CurrentUser"] as User_XModel;
    
    <div class="parameter">
        <div class="parameter_name">任务附件列表：</div>
    </div>
@*<input type="hidden" value="@(fileList)" id="fileListDetail" />*@
@*<input type="hidden"  value="@(currentUser.DisplayName)" id="userName"/>
    <input type="hidden"  value="@(currentUser.ID)" id="userID"/>*@
    
    <div class="padding10">
        <table id="FileList" class="" title="文件列表"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="ID" hidden="true"></th>
                    <th field="FileName" width="160" formatter="addLink">文件名称</th>
                    <th field="UploadTime" width="160" formatter="DateFormate">上传时间</th>
                    <th field="UpLoadUserID" hidden="true"></th>
                    <th field="UpLoadUserName" width="160">上传人</th>
                    @if (!IsTaskEnd)
                    {
                        <th field="Ope" width="160" formatter="OpeRender">操作</th>
                    }
                </tr>
            </thead>
        </table>
    </div>
    
    if (!IsTaskEnd)
    {
    <iframe name="targetUpload" src="/PlanManagement/FileUpload" border="0" frameborder="0" style="border: none;"></iframe>
    }
    
    
    <script type="text/javascript">

        var DateFormate = function (value, row, index) {
            if (value) {
                return value.DateStringConvert('yyyy-MM-dd');
            }
        };

        var OpeRender = function (value, row, index) {
            //if (value != true) return "";
            return '<a class="deleteRow">删除</a>';
        };

        var addLink = function (value, row, index) {
            if (value) {
                var path = row["UpLoadPath"]
                return '<a href="' + path + '" download>' + value + '</a>';
            }
        };



        TaskD.AppendFile = function (fileName) {
            if (fileName) {
                window.setTimeout(function () {
                    $('#FileList').datagrid('reload');
                }, 300);
            }
        };

        var saveTask = function () {
            var data = {};

            //文件列表
            var files = $('#FileList').datagrid("getData").rows;

            $.each(files, function (i, row) {
                var id = row["ID"];
                if (id) {
                    row["ID"] = id.toString();
                }
                delete row["Ope"];
            });

            //结束所有的编辑
            $('[data-field]').each(function () {
                var id = $(this).attr('id');
                var rows = $('#' + id).datagrid('getRows').length;
                for (var i = 0; i < rows; i++) {
                    $('#' + id).datagrid('endEdit', i);
                }
            });

            //任务巡检对象
            $('[data-field]').each(function () {
                var id = $(this).attr('id'),
                    propName = $(this).attr('data-field');

                if (propName) {
                    if ($(this)[0].tagName.toUpperCase() == "TABLE") {
                        data[propName] = $('#' + id).datagrid('getData').rows;
                    }
                }
            });

            data["TaskDetail"] = JSON.stringify(data);

            taskSave(data, files);
        };


        $(function () {

            $('#FileList').datagrid({
                url: '/PlanManagement/GetFileList',
                onClickCell: function (rowIndex, field, value) {
                    if (field == "Ope") {
                        $.messager.confirm('提醒', '确认删除这个文件吗？', function (r) {
                            if (r) {
                                $.post('/PlanManagement/FileDelete', {
                                    ID: $('#FileList').datagrid('getData').rows[rowIndex]["ID"]
                                }, function (res) {
                                    if (res == "OK") {
                                        $.messager.alert('提示', '删除成功!', 'info');
                                        $('#FileList').datagrid('reload');
                                    }
                                    if (res == "Error") {
                                        $.messager.alert('错误', '删除失败!', 'error');
                                    }
                                });
                                $('#FileList').datagrid('deleteRow', rowIndex);
                            }
                        });
                    }
                }
            });

            //var fileDetail = $('#fileListDetail').val();
            //if (fileDetail != "") {
            //    var list = JSON.parse(fileDetail);
            //    $.each(list, function (i, val) {
            //        val["UploadTime"] = DateFormate(val["UploadTime"]);
            //    });
            //    $('#FileList').datagrid({ data: list });
            //}

        });
    </script>
    
}

